﻿/// <reference path="../jquery-1.9.1.js" />
/// <reference path="../referraltracker.js" />

referraltracker.account.registeruser = (function () {

    function SaveUser() {
        if (Validate()) {
            var referrerId = $("#ParentReferralId").val();

            if (referrerId != "") {
                var data = {
                    referralId: referrerId
                };

                $.ajax({
                    url: '/Account/IsValidReferralId',
                    type: 'POST',
                    data: data,
                    dataType: 'json',
                    success: OnSaveUser
                });
            }
            else {
                $("#form1").submit();
            }
        }
    }

    function OnSaveUser(result) {
        if (result.isvalid) {
            $("#form1").submit();
        }
        else {
            alert("Referred Id is Invalid. Kindly place a valid Referred Id");
        }
    }

    function Validate() {
        var retVal = true;
        var password = $("#Password").val();
        var confirmPassword = $("#ConfirmPassword").val();

        if (retVal && password != confirmPassword) {
            alert("Confirm Password Failed");
            retVal = false;
        }

        return retVal;
    }
 
    var _instance = {
        saveUser: SaveUser
    };

    return _instance;
})();